#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 5 

struct Queue {
    int front;              
    int rear;               
    int data[MAX_SIZE];    
};

void initQueue(struct Queue *queue) {
    queue->front = 0;
    queue->rear = 0;
}

int isEmpty(struct Queue *queue) {
    return queue->front == queue->rear;
}

int isFull(struct Queue *queue) {
    return (queue->rear + 1) % MAX_SIZE == queue->front;
}

void enqueue(struct Queue *queue, int item) {
    if (isFull(queue)) {
        printf("Error: Queue is full\n");
        return;
    }
    queue->data[queue->rear] = item;
    queue->rear = (queue->rear + 1) % MAX_SIZE;
}

int dequeue(struct Queue *queue) {
    if (isEmpty(queue)) {
        printf("Error: Queue is empty\n");
        return -1;
    }
    int item = queue->data[queue->front];
    queue->front = (queue->front + 1) % MAX_SIZE;
    return item;
}

int getFront(struct Queue *queue) {
    if (isEmpty(queue)) {
        printf("Error: Queue is empty\n");
        return -1;
    }
    return queue->data[queue->front];
}

int getRear(struct Queue *queue) {
    if (isEmpty(queue)) {
        printf("Error: Queue is empty\n");
        return -1;
    }
    return queue->data[(queue->rear - 1 + MAX_SIZE) % MAX_SIZE];
}

int main() {
    struct Queue queue;
    initQueue(&queue);

    enqueue(&queue, 1);
    enqueue(&queue, 2);
    enqueue(&queue, 3);

    printf("Front element: %d\n", getFront(&queue));
    printf("Rear element: %d\n", getRear(&queue));

    while (!isEmpty(&queue)) {
        printf("%d ", dequeue(&queue));
    }

    return 0;
}